﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BAL;
namespace QuanLyTiemNET_DEV_LINQ
{
    public partial class XtraFormDangNhap : DevExpress.XtraEditors.XtraForm
    {
        public static string tenDN = null;
        public XtraFormDangNhap()
        {
            tenDN = null;
            InitializeComponent();
        }

        private void btnDN_Click(object sender, EventArgs e)
        {
            DataTableReader dtr = BAL_TAIKHOAN.LayTaiKhoan().CreateDataReader();
            while(dtr.Read())
            {
                if((dtr["TenDangNhap"].ToString().Equals(txtTenDN.Text)) && dtr["MatKhau"].ToString().Equals(txtMatKhau.Text))
                {
                    MessageBox.Show("Bạn đã đăng nhập với tên: " + txtTenDN.Text);
                    tenDN = txtTenDN.Text;
                    FrmMain.dangNhapThanhCong = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Tên đăng nhập hoặc tài khoản không đúng!!!!");
                    txtTenDN.ResetText();
                    txtMatKhau.ResetText();
                    txtTenDN.Focus();
                }

            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void XtraFormDangNhap_Load(object sender, EventArgs e)
        {
            txtTenDN.Focus();
        }

        private void txtTenDN_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                txtMatKhau.Focus();
        }

        private void txtMatKhau_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                btnDN_Click(sender, e);
        }
    }
}